﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Entities;
using ThoiTrang.Business;
using System.Collections.Generic;
using System.IO;

public partial class UserControls_ucMenuLeft : System.Web.UI.UserControl
{
    private int _groupId;

    public int GroupId
    {
        get { return _groupId; }
        set { _groupId = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

    protected string GetHtmlCode()
    {
        string codeStr = string.Empty;
        List<a_CatMain> catMains = a_CatMainService.Geta_CatMainListByGroup(GroupId);
        foreach (a_CatMain catMain in catMains)
        {
            codeStr += String.Format("\t\t\t\t<p class=\"cat\">{0}</p>", catMain.UName);
            codeStr += "\t\t\t\t<ul class=\"category\">";

            List<a_CatSub> catSubs = a_CatSubService.Geta_CatSubListByCatMain(catMain.CatID);
            for(int i=0;i<catSubs.Count;i++)
            {
                string link = ResolveUrl(TTHelper.GetDetailLink(catMain, catSubs[i]));
                if(i%2==0)
                    codeStr += String.Format("\t\t\t\t\t<li><a href=\"{0}\">{1}</a></li>", link, catSubs[i].UName);
                else
                    codeStr += String.Format("\t\t\t\t\t<li class=\"se\"><a href=\"{0}\">{1}</a></li>", link, catSubs[i].UName);
            }

            codeStr += "\t\t\t\t</ul>";
        }
        return codeStr;
    }

    protected string GetHtmlCodeFromFile()
    {
        try
        {
            a_CatGroup group = a_CatGroupService.Geta_CatGroup(GroupId);
            if (group == null) return string.Empty;
            string filename = group.GroupName.Replace(" ", "");
            filename = Server.MapPath(string.Format("Files/{0}.txt", filename));
            string res = string.Empty;

            FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(file);
            res = reader.ReadToEnd();

            res = res.Replace("ckid=", string.Concat("ckid=", SessionManager.GetCookie()));
            return res;
        }
        catch (Exception ex)
        {
            return string.Empty;
        }
    }
}
